/** 
 * CharsetFileChooser.java
 * @author Lex
 * 2007-8-31 ����10:11:27
 */
package org.lex.notepad.ui.filechooser;

import java.awt.Dimension;
import java.nio.charset.Charset;

import javax.swing.JFileChooser;
import javax.swing.border.EmptyBorder;

import org.lex.io.filesystem.TextDocumentFileFilter;


public class PreviewFileChooser extends JFileChooser {
	private PreviewPane previewPane = null;

	public PreviewFileChooser() {
		super();
		this.initialize();
	}

	public Charset getCharset() {
		return this.getPreviewPane().getCharset();
	}

	private void initialize() {
		// show hiding files
		this.setFileHidingEnabled(false);
		// single selection
		this.setMultiSelectionEnabled(false);
		// juse allow file selection
		this.setFileSelectionMode(JFileChooser.FILES_ONLY);
		// text file filter
		this.addChoosableFileFilter(TextDocumentFileFilter.getInstance());
		this.setFileFilter(TextDocumentFileFilter.getInstance());
		// preview pane
		this.setAccessory(this.getPreviewPane());
	}

	private PreviewPane getPreviewPane() {
		if (null == this.previewPane) {
			previewPane = new PreviewPane(this);
			previewPane.setBorder(new EmptyBorder(0, 5, 0, 0));
			previewPane.setPreferredSize(new Dimension(200, 275));
		}
		return this.previewPane;
	}
}
